package com.zgc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.zgc.dto.CountSaleDto;
import com.zgc.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper extends BaseMapper<Orders> {
    //查询最近一周的每天的销售额
    /**
     * 最近一周的销售额
     * */
    @Select("select DAYNAME(date(order_time)) sj,sum(o.amount) sl from orders  o where YEARWEEK(order_time)=YEARWEEK(date_sub(CURDATE(),INTERVAL 1 WEEK)) group by date(order_time)")
    List<CountSaleDto> countAmonutByWeek();

    /**
     * 最近一月的销售额
     * */
    @Select("select YEARWEEK(order_time) sj,sum(o.amount) sl from orders o where MONTH(order_time)=month(date_sub(CURDATE(),INTERVAL 1 MONTH)) group by YEARWEEK(order_time)")
    List<CountSaleDto> countAmonutByMonth();
    @Select("select c.name name,sum(o.amount) value from orders o,order_detail od,dish d,category c where o.id=od.order_id and od.dish_id=d.id and d.category_id=c.id group by c.name")
            List<Map> countAmonutByDish();
}
